#!/usr/bin/env python
# -*- coding:utf-8 -*- 
# Author: Jeokayne Ataier
import socket
import json

server = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
server.bind(("127.0.0.1",8881))
server.listen(10)
while True:
    conn,addr = server.accept()
    welcom_msg = "Welcome to Server!"
    conn.sendall(welcom_msg.encode("utf-8"))
    with open("account.json","r") as f:
        server_info = json.load(f)
    while True:
        is_ok = False
        data = conn.recv(1024).decode("utf-8")
        if not data:
            break
        client_info = json.loads(data)
        print(client_info)
        if client_info in server_info:
            echo_info = {"status":True,"msg":"登录成功！"}
            send_info = json.dumps(echo_info).encode("utf-8")
            conn.sendall(send_info)
            break
        else:
            echo_info = {"status":False,"msg":"登录失败！"}
            send_info = json.dumps(echo_info).encode("utf-8")
            conn.sendall(send_info)
    conn.close()
